﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductionManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductionManagement.ProdTransSnVMs
{
    public partial class ProdTransSnListVM : BasePagedListVM<ProdTransSn_View, ProdTransSnSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProdTransSn_View>> InitGridHeader()
        {
            return new List<GridColumn<ProdTransSn_View>>{
                
                this.MakeGridHeader(x => x.ProdTransSn_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_ProductId).SetTitle(@Localizer["Page.产品Id"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_ProductCode).SetTitle(@Localizer["Page.产品编码"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_Wo).SetTitle(@Localizer["Page.工单号"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CurLineId).SetTitle(@Localizer["Page.所在产线Id"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CurLineCode).SetTitle(@Localizer["Page.所在产线编号"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CurOpId).SetTitle(@Localizer["Page.所在工位"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CurOpCode).SetTitle(@Localizer["Page.所在工位编号"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CurRoutingId).SetTitle(@Localizer["Page.所在工艺路线"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CurRoutingCode).SetTitle(@Localizer["Page.所在工艺路线编号"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_InboundTime).SetTitle(@Localizer["Page.工位进站时间"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_OutboundTime).SetTitle(@Localizer["Page.工位出站时间"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_OnlineTime).SetTitle(@Localizer["Page.产品上线时间"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_OfflineTime).SetTitle(@Localizer["Page.产品下线时间"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_Stage).SetTitle(@Localizer["Page.工作阶段"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_IsCompelted).SetTitle(@Localizer["Page.完工"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CustomerSn).SetTitle(@Localizer["Page.客户SN"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_ReworkFlag).SetTitle(@Localizer["Page.返工标识"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_ReworkDoc).SetTitle(@Localizer["Page.返工单据"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_ReworkCount).SetTitle(@Localizer["Page.返修次数"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_NgSteps).SetTitle(@Localizer["Page.NG步序号集合"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_IsNeedRework).SetTitle(@Localizer["Page.是否需要进行返工"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ProdTransSn_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProdTransSn_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionTransSn>()
                
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.CurLineId, x=>x.CurLineId)
                .CheckContain(Searcher.CurLineCode, x=>x.CurLineCode)
                .CheckEqual(Searcher.CurOpId, x=>x.CurOpId)
                .CheckContain(Searcher.CurOpCode, x=>x.CurOpCode)
                .CheckEqual(Searcher.CurRoutingId, x=>x.CurRoutingId)
                .CheckContain(Searcher.CurRoutingCode, x=>x.CurRoutingCode)
                .CheckBetween(Searcher.InboundTime?.GetStartTime(), Searcher.InboundTime?.GetEndTime(), x => x.InboundTime, includeMax: false)
                .CheckBetween(Searcher.OutboundTime?.GetStartTime(), Searcher.OutboundTime?.GetEndTime(), x => x.OutboundTime, includeMax: false)
                .CheckBetween(Searcher.OnlineTime?.GetStartTime(), Searcher.OnlineTime?.GetEndTime(), x => x.OnlineTime, includeMax: false)
                .CheckBetween(Searcher.OfflineTime?.GetStartTime(), Searcher.OfflineTime?.GetEndTime(), x => x.OfflineTime, includeMax: false)
                .CheckEqual(Searcher.Stage, x=>x.Stage)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckEqual(Searcher.IsCompelted, x=>x.IsCompelted)
                .CheckContain(Searcher.CustomerSn, x=>x.CustomerSn)
                .CheckEqual(Searcher.ReworkFlag, x=>x.ReworkFlag)
                .CheckContain(Searcher.ReworkDoc, x=>x.ReworkDoc)
                .CheckEqual(Searcher.ReworkCount, x=>x.ReworkCount)
                .CheckContain(Searcher.NgSteps, x=>x.NgSteps)
                .CheckEqual(Searcher.IsNeedRework, x=>x.IsNeedRework)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProdTransSn_View
                {
				    ID = x.ID,
                    
                    ProdTransSn_Sn = x.Sn,
                    ProdTransSn_ProductId = x.ProductId,
                    ProdTransSn_ProductCode = x.ProductCode,
                    ProdTransSn_Wo = x.Wo,
                    ProdTransSn_CurLineId = x.CurLineId,
                    ProdTransSn_CurLineCode = x.CurLineCode,
                    ProdTransSn_CurOpId = x.CurOpId,
                    ProdTransSn_CurOpCode = x.CurOpCode,
                    ProdTransSn_CurRoutingId = x.CurRoutingId,
                    ProdTransSn_CurRoutingCode = x.CurRoutingCode,
                    ProdTransSn_InboundTime = x.InboundTime,
                    ProdTransSn_OutboundTime = x.OutboundTime,
                    ProdTransSn_OnlineTime = x.OnlineTime,
                    ProdTransSn_OfflineTime = x.OfflineTime,
                    ProdTransSn_Stage = x.Stage,
                    ProdTransSn_Status = x.Status,
                    ProdTransSn_IsCompelted = x.IsCompelted,
                    ProdTransSn_CustomerSn = x.CustomerSn,
                    ProdTransSn_ReworkFlag = x.ReworkFlag,
                    ProdTransSn_ReworkDoc = x.ReworkDoc,
                    ProdTransSn_ReworkCount = x.ReworkCount,
                    ProdTransSn_NgSteps = x.NgSteps,
                    ProdTransSn_IsNeedRework = x.IsNeedRework,
                    ProdTransSn_CreateTime = x.CreateTime,
                    ProdTransSn_UpdateTime = x.UpdateTime,
                    ProdTransSn_CreateBy = x.CreateBy,
                    ProdTransSn_UpdateBy = x.UpdateBy,
                    ProdTransSn_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProdTransSn_View: ProductionTransSn
    {
        
        public string ProdTransSn_Sn { get; set; }
        public long? ProdTransSn_ProductId { get; set; }
        public string ProdTransSn_ProductCode { get; set; }
        public string ProdTransSn_Wo { get; set; }
        public long? ProdTransSn_CurLineId { get; set; }
        public string ProdTransSn_CurLineCode { get; set; }
        public long? ProdTransSn_CurOpId { get; set; }
        public string ProdTransSn_CurOpCode { get; set; }
        public long? ProdTransSn_CurRoutingId { get; set; }
        public string ProdTransSn_CurRoutingCode { get; set; }
        public DateTime? ProdTransSn_InboundTime { get; set; }
        public DateTime? ProdTransSn_OutboundTime { get; set; }
        public DateTime? ProdTransSn_OnlineTime { get; set; }
        public DateTime? ProdTransSn_OfflineTime { get; set; }
        public SnStageEnum? ProdTransSn_Stage { get; set; }
        public SnStatusEnum? ProdTransSn_Status { get; set; }
        public bool? ProdTransSn_IsCompelted { get; set; }
        public string ProdTransSn_CustomerSn { get; set; }
        public ReworkFlagEnum? ProdTransSn_ReworkFlag { get; set; }
        public string ProdTransSn_ReworkDoc { get; set; }
        public int? ProdTransSn_ReworkCount { get; set; }
        public string ProdTransSn_NgSteps { get; set; }
        public bool? ProdTransSn_IsNeedRework { get; set; }
        public DateTime? ProdTransSn_CreateTime { get; set; }
        public DateTime? ProdTransSn_UpdateTime { get; set; }
        public string ProdTransSn_CreateBy { get; set; }
        public string ProdTransSn_UpdateBy { get; set; }
        public bool ProdTransSn_IsValid { get; set; }

    }

}